package com.combetter.changxing;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import static com.combetter.changxing.util.EncryptUtils.desDecrypt;

/**
 * 类名  ElectronicPipe
 * 作者  tlfx: Sean.guo
 * 日期  2019/2/22 10:28
 */
public class TestActivity {
    public static void main(String[] args) throws Exception {
////        // DES算法要求密鈅64位(8字节)
//        byte rawKeyData[] = "ZY%$ls19".getBytes("UTF-8");
//        File file = new File("D:\\Sean\\project_data\\电子烟\\8266_remoteV100.bin");
//        byte[] source = new byte[(int) file.length()];
//        FileInputStream is = new FileInputStream(file);
//        is.read(source, 0, (int) file.length());
//        is.close();
//        // 加密
//        byte[] enc = desEncrypt(source, rawKeyData);
//        System.out.println("desEncrypt:" + source.length + "->" + enc.length);
//        // 输出到文件
//        FileOutputStream os = new FileOutputStream(new File("D:\\Sean\\project_data\\电子烟\\desremoteV100.bin"));
//        os.write(enc, 0, enc.length);
//        os.close();

        /*------------------------------解密-------------------------------*/
//         DES算法要求密鈅64位(8字节)
        byte rawKeyData1[] = "ZY%$ls19".getBytes("UTF-8");
        File file1 = new File("D:\\Sean\\project_data\\电子烟\\V100.bin");
        byte[] data = new byte[(int) file1.length()];
        FileInputStream is1 = new FileInputStream(file1);
        is1.read(data, 0, (int) file1.length());
        is1.close();
        // 加密
        byte[] dec = desDecrypt(data, rawKeyData1);
        // 输出到文件
        FileOutputStream os1 = new FileOutputStream(new File("D:\\Sean\\project_data\\电子烟\\debin100.bin"));
        os1.write(dec, 0, dec.length);
        os1.close();
    }
}
